clear
set seed 0

set more off

global sDIR = "....INSERT YOUR DIRECTORY"

cd "$sDIR"

use "/clean_data_wave1.dta", clear

label define Group_label_new  1 "Control" 2 "lower LTI" 3 "higher LTI" 4 "lower LTV-BTL" 5 "higher LTV-BTL" 6 "lower LTV-Own" 7 "higher LTV-Own"
label value Group Group_label_new

foreach year in 1 5 {
	
	gen HP_`year'Y_diff = Post_HP_`year'Y - Pre_HP_`year'Y_point
	label var HP_`year'Y_diff "Change in `year'-year house price expectations"
	
	gen HP_`year'Y_diff_abs = abs(HP_`year'Y_diff)
	label var HP_`year'Y_diff_abs "Magnitude of change in `year'-year house price expectations"
	
}


foreach var in Pre_inflation Pre_unemp Pre_mortgage Pre_stock{
	
	tab Group, sum(`var')
	reg `var' ib(1).Group  [pw = weight], r

}


gen change_intention = Post_intention - Pre_intention
label define change_intention_label  -1 "Yes -> No" 0 "No change" 1 "No -> Yes"
label values change_intention change_intention_label
label var change_intention "Changed intention in buysing houses after treatment"

gen hp_revision = Post_HP_1Y-Pre_HP_1Y_point
gen hp_direction = .
replace hp_direction = 1 if hp_revision > 0
replace hp_direction = 0 if hp_revision == 0
replace hp_direction = -1 if hp_revision < 0

gen cat1=Post_reason_2+Post_reason_3+Post_reason_4
gen cat2=Post_reason_1
gen cat3=Post_reason_5+Post_reason_6+Post_reason_8+Post_reason_9

label var cat1 "Direct channel eﬀects"
label var cat2 "Price expectations"
label var cat3 "Equilibrium outcomes"

//----------------------------
//-------- Table 1  -------
//----------------------------
tab Income       [aw=weight]
tab Income       [aw=weight] if Group == 1
tab Income       [aw=weight] if Group == 2
tab Income       [aw=weight] if Group == 3
tab Income       [aw=weight] if Group == 4
tab Income       [aw=weight] if Group == 5
tab Income       [aw=weight] if Group == 6
tab Income       [aw=weight] if Group == 7

oneway Income Group [aw=weight] if Income <= 2
oneway Income Group [aw=weight] if Income <= 6

tab Homeown       [aw=weight]
tab Homeown       [aw=weight] if Group == 1
tab Homeown       [aw=weight] if Group == 2
tab Homeown       [aw=weight] if Group == 3
tab Homeown       [aw=weight] if Group == 4
tab Homeown       [aw=weight] if Group == 5
tab Homeown       [aw=weight] if Group == 6
tab Homeown       [aw=weight] if Group == 7

oneway Homeown Group [aw=weight]

tab No_mortgage       [aw=weight]
tab No_mortgage       [aw=weight] if Group == 1
tab No_mortgage       [aw=weight] if Group == 2
tab No_mortgage       [aw=weight] if Group == 3
tab No_mortgage       [aw=weight] if Group == 4
tab No_mortgage       [aw=weight] if Group == 5
tab No_mortgage       [aw=weight] if Group == 6
tab No_mortgage       [aw=weight] if Group == 7

oneway No_mortgage Group [aw=weight]


tab Educ        [aw=weight]
tab Educ        [aw=weight] if Group == 1
tab Educ        [aw=weight] if Group == 2
tab Educ        [aw=weight] if Group == 3
tab Educ        [aw=weight] if Group == 4
tab Educ        [aw=weight] if Group == 5
tab Educ        [aw=weight] if Group == 6
tab Educ        [aw=weight] if Group == 7

oneway Educ Group [aw=weight] if Educ >= 4

tab Liquid       [aw=weight]
tab Liquid       [aw=weight] if Group == 1
tab Liquid       [aw=weight] if Group == 2
tab Liquid       [aw=weight] if Group == 3
tab Liquid       [aw=weight] if Group == 4
tab Liquid       [aw=weight] if Group == 5
tab Liquid       [aw=weight] if Group == 6
tab Liquid       [aw=weight] if Group == 7

oneway Liquid Group [aw=weight] if Liquid >= 4


tab  Hhsize        [aw=weight]
tab  Hhsize        [aw=weight] if Group == 1
tab  Hhsize        [aw=weight] if Group == 2
tab  Hhsize        [aw=weight] if Group == 3
tab  Hhsize        [aw=weight] if Group == 4
tab  Hhsize        [aw=weight] if Group == 5
tab  Hhsize        [aw=weight] if Group == 6
tab  Hhsize        [aw=weight] if Group == 7

oneway Hhsize  Group [aw=weight]


tab Marr       [aw=weight]
tab Marr       [aw=weight] if Group == 1
tab Marr       [aw=weight] if Group == 2
tab Marr       [aw=weight] if Group == 3
tab Marr       [aw=weight] if Group == 4
tab Marr       [aw=weight] if Group == 5
tab Marr       [aw=weight] if Group == 6
tab Marr       [aw=weight] if Group == 7

oneway Marr  Group [aw=weight]

tab Child       [aw=weight]
tab Child       [aw=weight] if Group == 1
tab Child       [aw=weight] if Group == 2
tab Child       [aw=weight] if Group == 3
tab Child       [aw=weight] if Group == 4
tab Child       [aw=weight] if Group == 5
tab Child       [aw=weight] if Group == 6
tab Child       [aw=weight] if Group == 7

oneway Child  Group [aw=weight]

sum Age        [aw=weight]
sum Age        [aw=weight] if Group == 1
sum Age        [aw=weight] if Group == 2
sum Age        [aw=weight] if Group == 3
sum Age        [aw=weight] if Group == 4
sum Age        [aw=weight] if Group == 5
sum Age        [aw=weight] if Group == 6
sum Age        [aw=weight] if Group == 7

oneway Age  Group [aw=weight]

tab Sex        [aw=weight]
tab Sex        [aw=weight] if Group == 1
tab Sex        [aw=weight] if Group == 2
tab Sex        [aw=weight] if Group == 3
tab Sex        [aw=weight] if Group == 4
tab Sex        [aw=weight] if Group == 5
tab Sex        [aw=weight] if Group == 6
tab Sex        [aw=weight] if Group == 7

oneway Sex   Group [aw=weight]

gen four_regions = substr(oslaua,1,1) 
gen four_regions_E = 0
replace four_regions_E = 1 if four_regions == "E"

gen four_regions_N = 0
replace four_regions_N = 1 if four_regions == "N"

gen four_regions_S = 0
replace four_regions_S = 1 if four_regions == "S"

gen four_regions_W = 0
replace four_regions_W = 1 if four_regions == "W"

tab four_regions     [aw=weight]   
tab four_regions     [aw=weight]     if Group == 1
tab four_regions     [aw=weight]     if Group == 2
tab four_regions     [aw=weight]     if Group == 3
tab four_regions     [aw=weight]     if Group == 4
tab four_regions     [aw=weight]     if Group == 5
tab four_regions     [aw=weight]     if Group == 6
tab four_regions     [aw=weight]     if Group == 7

oneway four_regions_E   Group [aw=weight] 
oneway four_regions_N   Group [aw=weight] 
oneway four_regions_S   Group [aw=weight] 
oneway four_regions_W   Group [aw=weight]



//-----------------------------
//---------- Table 2 ----------
//-----------------------------
//column 1
reg HP_1Y_diff ib(1).Group Pre_inflation Pre_stock Pre_mortgage Pre_unemp  if inrange(HP_1Y_diff, -13.7, 15.8)  [pw = weight], r

//column 2
reghdfe HP_1Y_diff ib(1).Group Pre_inflation Pre_stock Pre_mortgage Pre_unemp if inrange(HP_1Y_diff, -13.7, 15.8)  [pw = weight], abs(Educ Marr Chi Hhsize Income LiquidAsset Sex employed Homeown) vce(r) baselevels

//column 3
reghdfe HP_1Y_diff ib(1).Group Pre_inflation Pre_stock Pre_mortgage Pre_unemp if inrange(HP_1Y_diff, -13.7, 15.8) & correct_1 + correct_2 + correct_3 == 3 [pw = weight], abs(Educ Marr Chi Hhsize Income Liquid Sex employed Homeown) vce(r) baselevels

//column 4
reg HP_5Y_diff ib(1).Group Pre_inflation Pre_stock Pre_mortgage Pre_unemp  if inrange(HP_5Y_diff,  -15.8, 15.3)  [pw = weight], r

//column 5
reghdfe HP_5Y_diff ib(1).Group Pre_inflation Pre_stock Pre_mortgage Pre_unemp if inrange(HP_5Y_diff,  -15.8, 15.3)  [pw = weight], abs(Educ Marr Chi Hhsize Income LiquidAsset Sex employed Homeown) vce(r) baselevels

//column 6
reghdfe HP_5Y_diff ib(1).Group Pre_inflation Pre_stock Pre_mortgage Pre_unemp if inrange(HP_5Y_diff, -15.8, 15.3) & correct_1 + correct_2 + correct_3 == 3 [pw = weight], abs(Educ Marr Chi Hhsize Income Liquid Sex employed Homeown) vce(r) baselevels



//-----------------------------
//---------- Table 4 ----------
//-----------------------------

reghdfe change_intention i.Group [pw = weight], nocon abs(Educ Marr Chi Hhsize Income LiquidAsset Sex employed) vce(r)
//compare the effectiveness of macro-prudential policies： tightening vs loosening
reghdfe change_intention ib(2).Group [pw = weight] if inlist(Group,2,4,6), abs(Educ Marr Chi Hhsize Income LiquidAsset Sex employed) vce(r) baselevels
reghdfe change_intention ib(3).Group [pw = weight] if inlist(Group,3,5,7), abs(Educ Marr Chi Hhsize Income LiquidAsset Sex employed) vce(r) baselevels

//-----------------------------
//---------- Table 5 ----------
//-----------------------------
//column 1
reghdfe Post_afford Post_reason_1 Post_reason_2 Post_reason_3 Post_reason_4 Post_reason_5 Post_reason_6 Post_reason_7 Post_reason_8 Post_reason_9 [pw = weight] if inlist(Group,2,3), abs(Educ Marr Chi Hhsize Income LiquidAsset Sex employed) vce(r) baselevels
//column 2
reghdfe Post_afford Post_reason_1 Post_reason_2 Post_reason_3 Post_reason_4 Post_reason_5 Post_reason_6 Post_reason_7 Post_reason_8 Post_reason_9 [pw = weight] if inlist(Group,4,5), abs(Educ Marr Chi Hhsize Income LiquidAsset Sex employed) vce(r) baselevels
//column 3
reghdfe Post_afford Post_reason_1 Post_reason_2 Post_reason_3 Post_reason_4 Post_reason_5 Post_reason_6 Post_reason_7 Post_reason_8 Post_reason_9 [pw = weight] if inlist(Group,6,7), abs(Educ Marr Chi Hhsize Income LiquidAsset Sex employed) vce(r) baselevels
//column 4
reghdfe Post_afford Post_reason_1 Post_reason_2 Post_reason_3 Post_reason_4 Post_reason_5 Post_reason_6 Post_reason_7 Post_reason_8 Post_reason_9 [pw = weight], abs(Educ Marr Chi Hhsize Income LiquidAsset Sex employed) vce(r) baselevels


//-----------------------------
//---------- Table 6 ----------
//-----------------------------
reg change_intention cat1 cat2 cat3 [pw = weight], cluster(Region)
ologit change_intention cat1 cat2 cat3 [pw = weight], cluster(Region)
oprobit change_intention cat1 cat2 cat3 [pw = weight], cluster(Region)


//-----------------------------
//---------- Table B.1 - B3 ---
//-----------------------------
// purely descriptive



//-----------------------------
//---------- Table B.4 ----------
//-----------------------------

encode RegionName, gen(region)

gen Pre_HP_1Y_prob = (Pre_HP_1Y_1*(-48) + Pre_HP_1Y_2*(-20) + Pre_HP_1Y_3*(-12) + Pre_HP_1Y_4*(-6) + Pre_HP_1Y_5*(-2) + Pre_HP_1Y_6*2+ Pre_HP_1Y_7*6 + Pre_HP_1Y_8*12 + Pre_HP_1Y_9*20 + Pre_HP_1Y_10*48)/100 

gen Pre_HP_1Y_prob2 = (Pre_HP_1Y_1*(-24) + Pre_HP_1Y_2*(-20) + Pre_HP_1Y_3*(-12) + Pre_HP_1Y_4*(-6) + Pre_HP_1Y_5*(-2) + Pre_HP_1Y_6*2+ Pre_HP_1Y_7*6 + Pre_HP_1Y_8*12 + Pre_HP_1Y_9*20 + Pre_HP_1Y_10*24)/100 

//1 year vs 1 year
foreach year in 1 {
	foreach var in 12M {
	
		reghdfe Pre_HP_`year'Y_prob change_`var' [pw = weight], abs(Educ Marr Chi Hhsize Income LiquidAsset Sex employed) cluster(oscty)
			
		reghdfe Pre_HP_`year'Y_prob change_`var' Pre_inflation Pre_stock Pre_mortgage Pre_unemp [pw = weight], abs(Educ Marr Chi Hhsize Income LiquidAsset Sex employed) cluster(oscty)
	}
}


foreach year in 1 {
	foreach var in 12M {
	
		reghdfe Pre_HP_`year'Y_prob change_`var'_county UA ldn [pw = weight], abs(Educ Marr Chi Hhsize Income LiquidAsset Sex employed first_one_digits) cluster(oscty)
			
		reghdfe Pre_HP_`year'Y_prob change_`var'_county UA ldn Pre_inflation Pre_stock Pre_mortgage Pre_unemp [pw = weight], abs(Educ Marr Chi Hhsize Income LiquidAsset Sex employed first_one_digits) cluster(oscty)
	}
}


//-----------------------------
//---------- Table B.5 --------
//-----------------------------
xtile change_12M_cat = change_12M , n(10)

//1-year
reghdfe HP_1Y_diff ib(1).Group Pre_inflation Pre_stock Pre_mortgage Pre_unemp  if inrange(HP_1Y_diff, -13.7, 15.8) & ( change_12M_cat == 10 |change_12M_cat == 9 | change_12M_cat == 8 ) [pw = weight], abs(Educ Marr Chi Hhsize Income Liquid Sex employed Homeown) vce(r) baselevels
	

reghdfe HP_1Y_diff ib(1).Group Pre_inflation Pre_stock Pre_mortgage Pre_unemp  if inrange(HP_1Y_diff, -13.7, 15.8) & ( change_12M_cat == 1 |change_12M_cat == 2 | change_12M_cat == 3 ) [pw = weight], abs(Educ Marr Chi Hhsize Income Liquid Sex employed Homeown) vce(r) baselevels

reghdfe HP_1Y_diff ib(1).Group Pre_inflation Pre_stock Pre_mortgage Pre_unemp  if inrange(HP_1Y_diff, -13.7, 15.8) & ( change_12M_cat == 10 |change_12M_cat == 9 | change_12M_cat == 8 | change_12M_cat == 7 ) [pw = weight], abs(Educ Marr Chi Hhsize Income Liquid Sex employed Homeown) vce(r) baselevels	

reghdfe HP_1Y_diff ib(1).Group Pre_inflation Pre_stock Pre_mortgage Pre_unemp  if inrange(HP_1Y_diff, -13.7, 15.8) & ( change_12M_cat == 1 |change_12M_cat == 2 | change_12M_cat == 3 | change_12M_cat == 4 ) [pw = weight], abs(Educ Marr Chi Hhsize Income Liquid Sex employed Homeown) vce(r) baselevels

reghdfe HP_1Y_diff ib(1).Group Pre_inflation Pre_stock Pre_mortgage Pre_unemp  if inrange(HP_1Y_diff, -13.7, 15.8) & ( change_12M_cat == 10 |change_12M_cat == 9 | change_12M_cat == 8 | change_12M_cat == 7 | change_12M_cat == 6 ) [pw = weight], abs(Educ Marr Chi Hhsize Income Liquid Sex employed Homeown) vce(r) baselevels

reghdfe HP_1Y_diff ib(1).Group Pre_inflation Pre_stock Pre_mortgage Pre_unemp  if inrange(HP_1Y_diff, -13.7, 15.8) & ( change_12M_cat == 1 |change_12M_cat == 2 | change_12M_cat == 3 | change_12M_cat == 4 | change_12M_cat == 5 ) [pw = weight], abs(Educ Marr Chi Hhsize Income Liquid Sex employed Homeown) vce(r) baselevels

// p values see excel "difference tests.xlsx"

//-----------------------------
//---------- Table B.6 --------
//-----------------------------

//5-year;
reghdfe HP_5Y_diff ib(1).Group Pre_inflation Pre_stock Pre_mortgage Pre_unemp  if inrange(HP_5Y_diff, -15.8, 15.3) & ( change_12M_cat == 10 |change_12M_cat == 9 | change_12M_cat == 8 ) [pw = weight], abs(Educ Marr Chi Hhsize Income Liquid Sex employed Homeown) vce(r) baselevels	

reghdfe HP_5Y_diff ib(1).Group Pre_inflation Pre_stock Pre_mortgage Pre_unemp  if inrange(HP_5Y_diff, -15.8, 15.3) & ( change_12M_cat == 1 |change_12M_cat == 2 | change_12M_cat == 3 ) [pw = weight], abs(Educ Marr Chi Hhsize Income Liquid Sex employed Homeown) vce(r) baselevels	

reghdfe HP_5Y_diff ib(1).Group Pre_inflation Pre_stock Pre_mortgage Pre_unemp  if inrange(HP_5Y_diff, -15.8, 15.3) & ( change_12M_cat == 10 |change_12M_cat == 9 | change_12M_cat == 8 | change_12M_cat == 7 ) [pw = weight], abs(Educ Marr Chi Hhsize Income Liquid Sex employed Homeown) vce(r) baselevels	

reghdfe HP_5Y_diff ib(1).Group Pre_inflation Pre_stock Pre_mortgage Pre_unemp  if inrange(HP_5Y_diff, -15.8, 15.3) & ( change_12M_cat == 1 |change_12M_cat == 2 | change_12M_cat == 3 | change_12M_cat == 4 ) [pw = weight], abs(Educ Marr Chi Hhsize Income Liquid Sex employed Homeown) vce(r) baselevels

reghdfe HP_5Y_diff ib(1).Group Pre_inflation Pre_stock Pre_mortgage Pre_unemp  if inrange(HP_5Y_diff, -15.8, 15.3) & ( change_12M_cat == 10 |change_12M_cat == 9 | change_12M_cat == 8 | change_12M_cat == 7 | change_12M_cat == 6 ) [pw = weight], abs(Educ Marr Chi Hhsize Income Liquid Sex employed Homeown) vce(r) baselevels	

reghdfe HP_5Y_diff ib(1).Group Pre_inflation Pre_stock Pre_mortgage Pre_unemp  if inrange(HP_5Y_diff, -15.8, 15.3) & ( change_12M_cat == 1 |change_12M_cat == 2 | change_12M_cat == 3 | change_12M_cat == 4 | change_12M_cat == 5 ) [pw = weight], abs(Educ Marr Chi Hhsize Income Liquid Sex employed Homeown) vce(r) baselevels

// p values see excel "difference tests.xlsx"


//-----------------------------
//---------- Table B.7 --------
//-----------------------------
reghdfe HP_1Y_diff ib(1).Group Pre_inflation Pre_stock Pre_mortgage Pre_unemp if inrange(HP_1Y_diff, -13.7, 15.8) & Income_q == 1 [pw = weight], abs(Educ Marr Chi Hhsize Income LiquidAsset Sex employed Homeown) vce(r) baselevels
	

reghdfe HP_1Y_diff ib(1).Group Pre_inflation Pre_stock Pre_mortgage Pre_unemp if inrange(HP_1Y_diff, -13.7, 15.8) & Income_q == 3 [pw = weight], abs(Educ Marr Chi Hhsize Income LiquidAsset Sex employed Homeown) vce(r) baselevels

reghdfe HP_1Y_diff ib(1).Group Pre_inflation Pre_stock Pre_mortgage Pre_unemp if inrange(HP_1Y_diff, -13.7, 15.8) & university == 0 [pw = weight], abs(Educ Marr Chi Hhsize Income LiquidAsset Sex employed Homeown) vce(r) baselevels

reghdfe HP_1Y_diff ib(1).Group Pre_inflation Pre_stock Pre_mortgage Pre_unemp if inrange(HP_1Y_diff, -13.7, 15.8) & university == 1 [pw = weight], abs(Educ Marr Chi Hhsize Income LiquidAsset Sex employed Homeown) vce(r) baselevels

reghdfe HP_1Y_diff ib(1).Group Pre_inflation Pre_stock Pre_mortgage Pre_unemp if inrange(HP_1Y_diff, -13.7, 15.8) & Homeowner_main == 1 [pw = weight], abs(Educ Marr Chi Hhsize Income LiquidAsset Sex employed Homeown) vce(r) baselevels

reghdfe HP_1Y_diff ib(1).Group Pre_inflation Pre_stock Pre_mortgage Pre_unemp if inrange(HP_1Y_diff, -13.7, 15.8) & Homeowner_main == 2 [pw = weight], abs(Educ Marr Chi Hhsize Income LiquidAsset Sex employed Homeown) vce(r) baselevels		

reghdfe HP_1Y_diff ib(1).Group Pre_inflation Pre_stock Pre_mortgage Pre_unemp if inrange(HP_1Y_diff, -13.7, 15.8) & Fixed_rate_mortgage == 1 [pw = weight], abs(Educ Marr Chi Hhsize Income LiquidAsset Sex employed Homeown) vce(r) baselevels

reghdfe HP_1Y_diff ib(1).Group Pre_inflation Pre_stock Pre_mortgage Pre_unemp if inrange(HP_1Y_diff, -13.7, 15.8) & Tracker_mortgage == 1 [pw = weight], abs(Educ Marr Chi Hhsize Income LiquidAsset Sex employed Homeown) vce(r) baselevels
	
reghdfe HP_1Y_diff ib(1).Group Pre_inflation Pre_stock Pre_mortgage Pre_unemp if inrange(HP_1Y_diff, -13.7, 15.8) & Age < 30 [pw = weight], abs(Educ Marr Chi Hhsize Income LiquidAsset Sex employed Homeown) vce(r) baselevels

reghdfe HP_1Y_diff ib(1).Group Pre_inflation Pre_stock Pre_mortgage Pre_unemp if inrange(HP_1Y_diff, -13.7, 15.8) & inrange(Age, 30, 49) [pw = weight], abs(Educ Marr Chi Hhsize Income LiquidAsset Sex employed Homeown) vce(r) baselevels

reghdfe HP_1Y_diff ib(1).Group Pre_inflation Pre_stock Pre_mortgage Pre_unemp if inrange(HP_1Y_diff, -13.7, 15.8) & Age >= 50 [pw = weight], abs(Educ Marr Chi Hhsize Income LiquidAsset Sex employed Homeown) vce(r) baselevels

//-----------------------------
//---------- Table B.8 --------
//-----------------------------
reghdfe HP_5Y_diff ib(1).Group Pre_inflation Pre_stock Pre_mortgage Pre_unemp if inrange(HP_5Y_diff, -15.8, 15.3) & Income_q == 1 [pw = weight], abs(Educ Marr Chi Hhsize Income LiquidAsset Sex employed Homeown) vce(r) baselevels

reghdfe HP_5Y_diff ib(1).Group Pre_inflation Pre_stock Pre_mortgage Pre_unemp if inrange(HP_5Y_diff, -15.8, 15.3)& Income_q == 3 [pw = weight], abs(Educ Marr Chi Hhsize Income LiquidAsset Sex employed Homeown) vce(r) baselevels

reghdfe HP_5Y_diff ib(1).Group Pre_inflation Pre_stock Pre_mortgage Pre_unemp if inrange(HP_5Y_diff, -15.8, 15.3) & university == 0 [pw = weight], abs(Educ Marr Chi Hhsize Income LiquidAsset Sex employed Homeown) vce(r) baselevels

reghdfe HP_5Y_diff ib(1).Group Pre_inflation Pre_stock Pre_mortgage Pre_unemp if inrange(HP_5Y_diff, -15.8, 15.3) & university == 1 [pw = weight], abs(Educ Marr Chi Hhsize Income LiquidAsset Sex employed Homeown) vce(r) baselevels

reghdfe HP_5Y_diff ib(1).Group Pre_inflation Pre_stock Pre_mortgage Pre_unemp if inrange(HP_5Y_diff, -15.8, 15.3) & Homeowner_main == 1 [pw = weight], abs(Educ Marr Chi Hhsize Income LiquidAsset Sex employed Homeown) vce(r) baselevels

reghdfe HP_5Y_diff ib(1).Group Pre_inflation Pre_stock Pre_mortgage Pre_unemp if inrange(HP_5Y_diff, -15.8, 15.3) & Homeowner_main == 2 [pw = weight], abs(Educ Marr Chi Hhsize Income LiquidAsset Sex employed Homeown) vce(r) baselevels

reghdfe HP_5Y_diff ib(1).Group Pre_inflation Pre_stock Pre_mortgage Pre_unemp if inrange(HP_5Y_diff, -15.8, 15.3) & Fixed_rate_mortgage == 1 [pw = weight], abs(Educ Marr Chi Hhsize Income LiquidAsset Sex employed Homeown) vce(r) baselevels

reghdfe HP_5Y_diff ib(1).Group Pre_inflation Pre_stock Pre_mortgage Pre_unemp if inrange(HP_5Y_diff, -15.8, 15.3) & Tracker_mortgage == 1 [pw = weight], abs(Educ Marr Chi Hhsize Income LiquidAsset Sex employed Homeown) vce(r) baselevels

reghdfe HP_5Y_diff ib(1).Group Pre_inflation Pre_stock Pre_mortgage Pre_unemp if inrange(HP_5Y_diff, -15.8, 15.3) & Age < 30 [pw = weight], abs(Educ Marr Chi Hhsize Income LiquidAsset Sex employed Homeown) vce(r) baselevels

reghdfe HP_5Y_diff ib(1).Group Pre_inflation Pre_stock Pre_mortgage Pre_unemp if inrange(HP_5Y_diff, -15.8, 15.3) & inrange(Age, 30, 49) [pw = weight], abs(Educ Marr Chi Hhsize Income LiquidAsset Sex employed Homeown) vce(r) baselevels

reghdfe HP_5Y_diff ib(1).Group Pre_inflation Pre_stock Pre_mortgage Pre_unemp if inrange(HP_5Y_diff, -15.8, 15.3) & Age >= 50 [pw = weight], abs(Educ Marr Chi Hhsize Income LiquidAsset Sex employed Homeown) vce(r) baselevels


//-----------------------------
//---------- Table B.9 --------
//-----------------------------
reghdfe Pre_intention ib(1).Group [pw = weight], abs(Educ Marr Chi Hhsize Income LiquidAsset Sex employed) vce(r) baselevels
reghdfe Pre_intention_type_1 ib(1).Group [pw = weight] if Pre_intention == 1, abs(Educ Marr Chi Hhsize Income LiquidAsset Sex employed) vce(r) baselevels
reghdfe Pre_intention_type_2 ib(1).Group [pw = weight] if Pre_intention == 1, abs(Educ Marr Chi Hhsize Income LiquidAsset Sex employed) vce(r) baselevels
reghdfe Pre_intention_type_3 ib(1).Group [pw = weight] if Pre_intention == 1, abs(Educ Marr Chi Hhsize Income LiquidAsset Sex employed) vce(r) baselevels


ologit change_intention i.Group i.Educ i.Marr i.Chi i.Hhsize i.Income i.Liquid i.Sex i.employed [pw = weight],  vce(r)
ologit change_intention ib(2).Group i.Educ i.Marr i.Chi i.Hhsize i.Income i.Liquid i.Sex i.employed [pw = weight] if inlist(Group,2,4,6), vce(r) baselevels
ologit change_intention ib(3).Group i.Educ i.Marr i.Chi i.Hhsize i.Income i.Liquid i.Sex i.employed [pw = weight] if inlist(Group,3,5,7), vce(r) baselevels

//-----------------------------
//---------- Table B.10 -------
//-----------------------------
oprobit change_intention i.Group i.Educ i.Marr i.Chi i.Hhsize i.Income i.Liquid i.Sex i.employed [pw = weight],  vce(r)
oprobit change_intention ib(2).Group i.Educ i.Marr i.Chi i.Hhsize i.Income i.Liquid i.Sex i.employed [pw = weight] if inlist(Group,2,4,6), vce(r) baselevels
oprobit change_intention ib(3).Group i.Educ i.Marr i.Chi i.Hhsize i.Income i.Liquid i.Sex i.employed [pw = weight] if inlist(Group,3,5,7), vce(r) baselevels

//-----------------------------
//---------- Table B.11 ----------
//-----------------------------
ologit change_intention i.Group i.Educ i.Marr i.Chi i.Hhsize i.Income i.Liquid i.Sex i.employed [pw = weight],  vce(r)
ologit change_intention ib(2).Group i.Educ i.Marr i.Chi i.Hhsize i.Income i.Liquid i.Sex i.employed [pw = weight] if inlist(Group,2,4,6), vce(r) baselevels
ologit change_intention ib(3).Group i.Educ i.Marr i.Chi i.Hhsize i.Income i.Liquid i.Sex i.employed [pw = weight] if inlist(Group,3,5,7), vce(r) baselevels


//-----------------------------
//---------- Table B.12 -------
//-----------------------------
reg BetterTime_BuyHouse ibn.Group i.Educ i.Marr i.Chi i.Hhsize i.Income i.LiquidAsset i.Sex i.employed [pw = weight] if Group != 1 , r nocon
reg BetterTime_SellHouse ibn.Group i.Educ i.Marr i.Chi i.Hhsize i.Income i.LiquidAsset i.Sex i.employed [pw = weight] if Group != 1 , r nocon
reg BetterTime_Remortgage ibn.Group i.Educ i.Marr i.Chi i.Hhsize i.Income i.LiquidAsset i.Sex i.employed [pw = weight] if Group != 1 , r nocon
reg BetterTime_InvestStock ibn.Group i.Educ i.Marr i.Chi i.Hhsize i.Income i.LiquidAsset i.Sex i.employed [pw = weight] if Group != 1 , r nocon


//-----------------------------
//---------- Table B.13 -------
//-----------------------------
reg Post_afford Post_reason_1 Post_reason_2 Post_reason_3 Post_reason_4 Post_reason_5 Post_reason_6 Post_reason_7 Post_reason_8 Post_reason_9 i.Educ i.Marr i.Chi i.Hhsize i.Income i.Liquid i.Sex i.employed [pw = weight], vce(r)

reg Post_afford Post_reason_1 Post_reason_2 Post_reason_3 Post_reason_4 Post_reason_5 Post_reason_6 Post_reason_7 Post_reason_8 Post_reason_9 i.Educ i.Marr i.Chi i.Hhsize i.Income i.Liquid i.Sex i.employed [pw = weight] if Group==2 , vce(r) baselevels

reg Post_afford Post_reason_1 Post_reason_2 Post_reason_3 Post_reason_4 Post_reason_5 Post_reason_6 Post_reason_7 Post_reason_8 Post_reason_9 i.Educ i.Marr i.Chi i.Hhsize i.Income i.Liquid i.Sex i.employed [pw = weight] if Group==3 , vce(r) baselevels

reg Post_afford Post_reason_1 Post_reason_2 Post_reason_3 Post_reason_4 Post_reason_5 Post_reason_6 Post_reason_7 Post_reason_8 Post_reason_9 i.Educ i.Marr i.Chi i.Hhsize i.Income i.Liquid i.Sex i.employed [pw = weight] if Group==4 , vce(r) baselevels

reg Post_afford Post_reason_1 Post_reason_2 Post_reason_3 Post_reason_4 Post_reason_5 Post_reason_6 Post_reason_7 Post_reason_8 Post_reason_9 i.Educ i.Marr i.Chi i.Hhsize i.Income i.Liquid i.Sex i.employed [pw = weight] if Group==5 , vce(r) baselevels

reg Post_afford Post_reason_1 Post_reason_2 Post_reason_3 Post_reason_4 Post_reason_5 Post_reason_6 Post_reason_7 Post_reason_8 Post_reason_9 i.Educ i.Marr i.Chi i.Hhsize i.Income i.Liquid i.Sex i.employed [pw = weight] if Group==6 , vce(r) baselevels

reg Post_afford Post_reason_1 Post_reason_2 Post_reason_3 Post_reason_4 Post_reason_5 Post_reason_6 Post_reason_7 Post_reason_8 Post_reason_9 i.Educ i.Marr i.Chi i.Hhsize i.Income i.Liquid i.Sex i.employed [pw = weight] if Group==7 , vce(r) baselevels

//-----------------------------
//---------- Table B.14 -------
//-----------------------------
reghdfe Post_change_Total HP_1Y_diff Pre_inflation Pre_stock Pre_mortgage Pre_unemp i.Homeown i.Pre_intention if inrange(Post_change_Total, -50, 200) [pw = weight], abs(Group Educ Marr Chi Hhsize Income LiquidAsset Sex employed Group) cluster(Group)

reghdfe Post_change_Total HP_1Y_diff Pre_HP_1Y_point Pre_inflation Pre_stock Pre_mortgage Pre_unemp i.Homeown i.Pre_intention if inrange(Post_change_Total, -50, 200) [pw = weight], abs(Group Educ Marr Chi Hhsize Income LiquidAsset Sex employed Group) cluster(Group)

reghdfe Post_change_Total HP_5Y_diff Pre_inflation Pre_stock Pre_mortgage Pre_unemp i.Homeown i.Pre_intention if inrange(Post_change_Total, -50, 200) [pw = weight], abs(Group Educ Marr Chi Hhsize Income LiquidAsset Sex employed Group) cluster(Group)

reghdfe Post_change_Total HP_5Y_diff Pre_HP_5Y_point Pre_inflation Pre_stock Pre_mortgage Pre_unemp i.Homeown i.Pre_intention if inrange(Post_change_Total, -50, 200) [pw = weight], abs(Group Educ Marr Chi Hhsize Income LiquidAsset Sex employed Group) cluster(Group)


	  
//Figure 1
	  
	foreach year in 1 {

distplot HP_`year'Y_diff if inlist(Group,2,3) & inrange(HP_1Y_diff, -20, 20), over(Group) scheme(s1color) c(J J) lc(red blue) lpattern("l" "--") yla(0 "0" 1 "1" 0.2(0.2)0.8, format ("%02.1f") ang(h)) title("Change in LTI ratio", size(large)) graphregion(color(white)) ylab(,nogrid) yline(0.2 0.4 0.6 0.8, lwidth(0.1pt) lcolor(gs12)) xtitle(,size(large)) ytitle(,size(large)) xlabel(,labsize(medlarge)) ylabel(,labsize(medlarge)) legend(label(1 "tightening") label(2 "loosening") rows(2) ring(0) position(4) region(lcolor(none)) size(medlarge))
	
distplot HP_`year'Y_diff if inlist(Group,4,5) & inrange(HP_1Y_diff, -20, 20), over(Group) scheme(s1color) c(J J) lc(red blue) lpattern("l" "--") yla(0 "0" 1 "1" 0.2(0.2)0.8, format ("%02.1f") ang(h)) title("Change in LTV-BTL ratio", size(large)) graphregion(color(white)) ylab(,nogrid) yline(0.2 0.4 0.6 0.8, lwidth(0.1pt) lcolor(gs12)) xtitle(,size(large)) ytitle(,size(large)) xlabel(,labsize(medlarge)) ylabel(,labsize(medlarge)) legend(label(1 "tightening") label(2 "loosening") rows(2) ring(0) position(4) region(lcolor(none)) size(medlarge))
		 
distplot HP_`year'Y_diff if inlist(Group,6,7) & inrange(HP_1Y_diff, -20, 20), over(Group) scheme(s1color) c(J J) lc(red blue) lpattern("l" "--") yla(0 "0" 1 "1" 0.2(0.2)0.8, format ("%02.1f") ang(h)) title("Change in LTV-Own ratio", size(large)) graphregion(color(white)) ylab(,nogrid) yline(0.2 0.4 0.6 0.8, lwidth(0.1pt) lcolor(gs12)) xtitle(,size(large)) ytitle(,size(large)) xlabel(,labsize(medlarge)) ylabel(,labsize(medlarge)) legend(label(1 "tightening") label(2 "loosening") rows(2) ring(0) position(4) region(lcolor(none)) size(medlarge))
}

/stop

foreach year in 5 {

 distplot HP_`year'Y_diff if inlist(Group,2,3) & inrange(HP_5Y_diff, -20, 20), over(Group) scheme(s1color) c(J J) lc(red blue) lpattern("l" "--") yla(0 "0" 1 "1" 0.2(0.2)0.8, format ("%02.1f") ang(h)) title("Change in LTI ratio", size(large)) graphregion(color(white)) ylab(,nogrid) yline(0.2 0.4 0.6 0.8, lwidth(0.1pt) lcolor(gs12)) xtitle(,size(large)) ytitle(,size(large)) xlabel(,labsize(medlarge)) ylabel(,labsize(medlarge)) legend(label(1 "tightening") label(2 "loosening") rows(2) ring(0) position(4) region(lcolor(none)) size(medlarge))
 
 distplot HP_`year'Y_diff if inlist(Group,4,5) & inrange(HP_5Y_diff, -20, 20), over(Group) scheme(s1color) c(J J) lc(red blue) lpattern("l" "--") yla(0 "0" 1 "1" 0.2(0.2)0.8, format ("%02.1f") ang(h)) title("Change in LTV-BTL ratio", size(large)) graphregion(color(white)) ylab(,nogrid) yline(0.2 0.4 0.6 0.8, lwidth(0.1pt) lcolor(gs12)) xtitle(,size(large)) ytitle(,size(large)) xlabel(,labsize(medlarge)) ylabel(,labsize(medlarge)) legend(label(1 "tightening") label(2 "loosening") rows(2) ring(0) position(4) region(lcolor(none)) size(medlarge))
	     
distplot HP_`year'Y_diff if inlist(Group,6,7) & inrange(HP_5Y_diff, -20, 20), over(Group) scheme(s1color) c(J J) lc(red blue) lpattern("l" "--") yla(0 "0" 1 "1" 0.2(0.2)0.8, format ("%02.1f") ang(h))  title("Change in LTV-Own ratio", size(large)) graphregion(color(white)) ylab(,nogrid) yline(0.2 0.4 0.6 0.8, lwidth(0.1pt) lcolor(gs12)) xtitle(,size(large)) ytitle(,size(large)) xlabel(,labsize(medlarge)) ylabel(,labsize(medlarge)) legend(label(1 "tightening") label(2 "loosening") rows(2) ring(0) position(4) region(lcolor(none)) size(medlarge))
	    
}

	 
//-----------------------------
//---------- Table 3 ----------
// -- robustness wave survey --
//-----------------------------

clear
capture log close _all
set seed 0

set more off

local date "2025"


cd "$sDIR/"

use "$sDIR/clean_data_wave2.dta", clear


foreach year in 1 5 {
	
	gen HP_`year'Y_diff = Post_HP_`year'Y - Pre_HP_`year'Y_point
	label var HP_`year'Y_diff "Change in `year'-year house price expectations"

}

foreach year in 1 5 {
	
	reg HP_`year'Y_diff ib(1).Group Pre_HP_`year'Y_point, r
    reghdfe HP_`year'Y_diff ib(1).Group Pre_HP_`year'Y_point if inrange(HP_1Y_diff, -13.7, 15.8)  [pw = weight],  abs(Educ Marr Chi Hhsize Income LiquidAsset Sex employed Homeown) vce(r) baselevels
	reghdfe HP_`year'Y_diff ib(1).Group Pre_HP_`year'Y_point if inrange(HP_1Y_diff, -13.7, 15.8) & correct_1+correct_2+correct_3 == 3  [pw = weight],  abs(Educ Marr Chi Hhsize Income LiquidAsset Sex employed Homeown) vce(r) baselevels

}


